package com.codeplateform.controller;

import com.codeplateform.common.ResultModel;
import com.codeplateform.dao.entity.Register;
import com.codeplateform.service.RegisterService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@RestController
@CrossOrigin
public class RegisterController {


    @Autowired
    RegisterService registerService;

    @PostMapping("/register")
    public ResultModel register(@RequestBody Register register) {

        log.info("注册方法入参为:{}", register);
        register.setRemark(0);
        register.setCreateTime(new Date());

        register.setAuth(0);
        register.setUserId(RandomStringUtils.randomNumeric(16));
//        register.setBirthday( new SimpleDateFormat("EEE dd MMM yyyy HH:mm:ss 'GMT'Z").format(new Date()));
        int insert = registerService.insert(register);

        if (insert == 1) {
            return ResultModel.success("200", "注册成功");
        } else {
            return ResultModel.error("500", "注册失败");
        }

    }
}
